package test3;

public class Vehicles {
	private Integer st_jam;
	private Integer st_menit;
	private Integer en_jam;
	private Integer en_menit;
	private Integer jamPertama;
	private Integer bayarPerJam;
	//private Integer diffTime;
	
	public void check_type(int type){
		if(type==1){
			this.bayarPerJam = 1000;
			this.jamPertama = 2000;
		}
		else if(type==2){
			this.bayarPerJam = 500;
			this.jamPertama = 1500;
		}
	}
	
	public void start_time(String st_time){
		this.st_jam = Integer.parseInt(st_time.substring(0, st_time.indexOf(":")));
		this.st_menit = Integer.parseInt(st_time.substring(st_time.indexOf(":")+1,st_time.length()));
		if(this.st_jam < 0 || this.st_jam > 12) throw new IllegalArgumentException("Jam harus bernilai 0-12");
		if(this.st_menit < 0 || this.st_menit > 59) throw new IllegalArgumentException("Menit harus bernilai 0-59");
	}
	
	public void end_time(String en_time){
		this.en_jam = Integer.parseInt(en_time.substring(0, en_time.indexOf(":")));
		this.en_menit = Integer.parseInt(en_time.substring(en_time.indexOf(":")+1,en_time.length()));
		if(this.en_jam < 0 || this.en_jam > 12) throw new IllegalArgumentException("Jam harus bernilai 0-12");
		if(this.en_menit < 0 || this.en_menit > 59) throw new IllegalArgumentException("Menit harus bernilai 0-59");
	}
	
	public Integer time_dif(){
		int diff = 0;
		if(this.en_jam <= 10 && this.en_jam >= 1) this.en_jam += 12; 
		if(this.st_jam >=1 && this.st_jam < 8) this.st_jam += 12;
			
		if(this.en_jam > this.st_jam){
			if(this.en_menit > this.st_menit)diff = this.en_jam - this.st_jam - 1;
			else diff = this.en_jam - this.st_jam - 2;
		}
		return diff;
		
	}
		
	public void totalFee(int type){
		int total = 0;
		int max = 0;
		total = this.jamPertama + time_dif() * this.bayarPerJam;
		System.out.println("Total Fee = Rp." + this.jamPertama + " + " + time_dif() +
							" x Rp." + this.bayarPerJam + " = Rp." + total);
		if(type == 1){
			if(total > 8000) max = 8000;
			else max = total;
		}
		else{
			if(total > 4000) max = 4000;
			else max = total;
		}
		
		System.out.println("Charge = Rp. " + max);
	}
}
